package com.body;

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.connect.connect;

public class delete_message extends HttpServlet{
	private HttpSession session;  //session
	private PrintWriter out;
	private connect conn;
	private String id;
	private Connection con ;
	private Statement stat;
	private String mutex = "";           
	
	@Override
	public void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		// TODO Auto-generated method stub
		 synchronized (mutex){
		    resp.setHeader("Content-type", "text/html;charset=utf-8");  
			out = resp.getWriter();
			
			id = req.getParameter("id");
			
			conn = new connect();
			con = conn.con();
			try{
				stat = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY);
				stat.executeUpdate("DELETE FROM message WHERE id= '"+id+"'");
			    out.print("<script  type='text/javascript'  >; window.location.href=document.referrer;  </script>");
				con.close();	
			}catch(SQLException e){
				e.printStackTrace();
			}
		 }
	}
	
	@Override
	public void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		// TODO Auto-generated method stub
		doPost(req,resp);
	}
}
